package cn.tsvtc.health.service.impl;


import cn.tsvtc.health.common.entity.PageResult;
import cn.tsvtc.health.common.entity.QueryPageBean;
import cn.tsvtc.health.mapper.CheckGroupCheckItemMapper;
import cn.tsvtc.health.mapper.CheckGroupMapper;
import cn.tsvtc.health.pojo.CheckGroup;
import cn.tsvtc.health.pojo.CheckGroupCheckItem;
import cn.tsvtc.health.pojo.CheckItem;
import cn.tsvtc.health.service.CheckGroupCheckItemService;
import cn.tsvtc.health.service.CheckGroupService;
import com.alibaba.dubbo.common.utils.StringUtils;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @author: Athena
 * @date: 2020/11/16 16:29
 * @description:
 */
@Service
public class CheckGroupCheckItemServiceImpl implements CheckGroupCheckItemService {

    @Autowired
    CheckGroupCheckItemMapper checkGroupCheckItemMapper;


    @Override
    public PageResult findAll(QueryPageBean queryPageBean) {
        Integer currentPage = queryPageBean.getCurrentPage();
        if(currentPage == null || currentPage <= 0){
            //非法页码
            currentPage = 1;
        }

        Integer pageSize = queryPageBean.getPageSize();
        if(pageSize == null || pageSize <= 0){
            //非法页大小
            pageSize = 10;
        }

        String queryString = queryPageBean.getQueryString();

        if(queryString == null) {
            queryString = "";
        } else if(!StringUtils.isBlank(queryString)){
            //不是null也不是""，有可能是 "   "
            queryString = queryString.trim();
        }

        queryString = "%" + queryString + "%";

        //queryString 一定有值   "%%"
        PageHelper.startPage(currentPage, pageSize);
        List<CheckGroupCheckItem> list = checkGroupCheckItemMapper.findByCondition(queryString);
        //分页对象
        PageInfo<CheckGroupCheckItem> pageInfo = new PageInfo<>(list);

        return new PageResult(pageInfo.getTotal(), pageInfo.getList());
    }

    @Override
    public int delete(Integer id) {
        return 0;
    }

    @Override
    public int update(CheckGroupCheckItem checkGroupCheckItem) {
        return 0;
    }

    @Override
    public int insert(CheckGroupCheckItem checkGroupCheckItem) {
        return 0;
    }

    /**
     * 根据组ID查询
     *
     * @param id
     * @return
     */
    @Override
    public List<CheckGroupCheckItem> findByCheckGroupId(Integer id) {
        List<CheckGroupCheckItem> byCheckGroupId = checkGroupCheckItemMapper.findByCheckGroupId(id);
        return byCheckGroupId;
    }

    /**
     * 根据item ID查询
     *
     * @param id
     * @return
     */
    @Override
    public List<CheckGroupCheckItem> findByCheckItemId(Integer id) {
        List<CheckGroupCheckItem> byCheckItemId = checkGroupCheckItemMapper.findByCheckItemId(id);
        return byCheckItemId;
    }
}
